<?php

// This class contains all of functions we need for the project
class All_Functions {

	// Here we define all of our variables
	var $number, $totalDivisors, $i, $s;
	
	// A construct value to pass the user number into $number
	function __construct($input_number) {
		// We specify that here:
		$this->setNumber($input_number);
	}
	
	function setNumber($value) {
		$this->number = $value;
	}
	
	function getNumber() {
		return $this->number;
	}
	
	function getTotalDivisors() {
		return $this->totalDivisors;
	}
	function incrementTotalDivisors() {
		$this->totalDivisors++;
	}
	
	// This function will count all possible divisors of the number. We need that in 2 other functions, so we are not returning any value
	function count_divisors() {
		
		// Just to make sure the total_divisors is 0
		$this->totalDivisors = 0;
		// Divide the number by every int that has lower or equal value. If the value is higher, then it's not a divisor.
		for($i=1; $i <= $this->getNumber(); $i++) {
			// Now divide it, but only if the remaining is 0.
			if ($this->getNumber() % $i == 0) {
				// If the $i has come all the way to here, that means it's a divisor. So, add one to the divisors.
				$this->incrementTotalDivisors();
			}
		}
	}
	
	// This function gets amount of divisors possible
	function get_divisors_count() {
		// We first need to count them using the function above
		$this->count_divisors();
		// Then we can return a value
		$this->getTotalDivisors();
	}
	
	// This function uses the count_divisors() function to check is a number prime or composite
	function number_complexity() {
		// We need to count divisors for this to work
		$this->count_divisors();
		// This is from algebra: If a number has more than 2 divisors, it's COMPOSITE. Only numbers that are divisible with 1 and themself are PRIME numbers.
		if($this->getTotalDivisors() > 2) {
			// Echo out "composite"
			echo 'composite';
		} 
		// Since the number of divisors isn't bigger than 2, that means it's 1 or 2 - so it's a PRIME number.
		else {
			echo 'prime';
		}
	}
	
	// This function writes down all of the divisors
	function number_division_ability() {
		// Divides the number with every number smaller or equal to it
		for ($s=1; $s <= $this->getNumber(); $s++) {
			// And if there is no remaining
			if ($this->getNumber() % $s == 0) {
				// It writes divisor down
				echo $s . ', ';
			}
		}
	}
	
}
?>